package com.service.business.member.controller;

import com.service.business.base.dto.LoginUserSession;
import com.service.business.framework.log.RequestLog;
import com.service.business.member.controller.rep.MemberWalletRep;
import com.service.business.member.controller.req.MemberWalletPageReq;
import com.service.business.member.controller.req.MemberWalletReq;
import com.service.business.member.controller.req.WalletDepositAddressReq;
import com.service.business.member.service.MemberWalletService;
import com.service.core.rest.BaseController;
import com.service.core.rest.response.BaseResponse;
import com.service.core.rest.response.OneResponse;
import com.service.core.rest.response.PageResponse;
import com.service.dao.enums.CoinsEnum;
import com.service.dao.enums.WalletEnums;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <dl>
 * <dt>back-end</dt>
 * <dd>Description:</dd>
 * <dd>Copyright: Copyright (C) 2015</dd>
 * <dd>Company: </dd>
 * <dd>CreateDate: 2019年09月21日</dd>
 * </dl>
 *
 * @author
 */
@Slf4j
@RestController()
@RequestMapping("member-wallet")
@Api(tags = "会员钱包相关信息")
public class MemberWalletController extends BaseController {

    @Autowired
    private MemberWalletService memberWalletService;

    @ApiOperation("钱包列表")
    @RequestLog("钱包列表")
    @PostMapping("page")
    public PageResponse<MemberWalletRep> page(@RequestBody MemberWalletPageReq pageReq) {
        pageReq.setBizType(WalletEnums.BizType.withdraw.getCode());
        return successQueryPageResponse(memberWalletService.pageWallet(pageReq));
    }


    @ApiOperation("新增钱包")
    @RequestLog("新增钱包")
    @PostMapping("new")
    public BaseResponse newWallet(@ApiParam @RequestBody @Validated MemberWalletReq walletReq) {
        walletReq.setBType(WalletEnums.BizType.withdraw);
        memberWalletService.doAddWallet(walletReq);
        return successUpdateBaseResponse();
    }

    @ApiOperation("删除钱包")
    @RequestLog("删除钱包")
    @PostMapping("delete/{id}")
    public BaseResponse deleteWallet(@ApiParam @PathVariable("id") Integer id) {
        memberWalletService.doDeleteWallet(id);
        return successUpdateBaseResponse();
    }

    @RequestLog("获取充值钱包")
    @ApiOperation("获取充值钱包")
    @PostMapping("deposit-address/{coin}")
    public OneResponse<MemberWalletRep> getMemberDepositAddress(@PathVariable("coin") CoinsEnum coin,
                                                                @RequestBody WalletDepositAddressReq addressReq) {
        return successQueryOneResponse(memberWalletService.getMemberDepositAddress(coin, addressReq.getWalletType()));
    }
}
